| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wp-content/plugins/wpmudev-updates/assets/src/js/widget/views/ |
Upload File : |
import React from 'react';
import HeaderRow from './rows/header'
import eventBus from './../helpers/event-bus';
import ajaxRequest from './../helpers/request';
import PeriodSelector from './../components/period-selector';
import MetricSelector from './../components/metric-selector';
import TablePagination from './../components/table-pagination';
export default class ListContent extends React.Component {
constructor(props) {
super(props);
this.state = {
currentMetric: '',
currentPage: 1,
list: [],
perPage: 10,
loading: false,
}
// Bind events.
this.handleRowClick = this.handleRowClick.bind(this);
this.handlePaginate = this.handlePaginate.bind(this);
this.handleMetricChange = this.handleMetricChange.bind(this);
}
/**
* Setup required properties.
*
* @since 4.11.4
*/
componentDidMount() {
let metrics = this.props.metrics;
// Set current metric to first one.
if (metrics.length > 0) {
this.setState({
currentMetric: metrics[0].key,
})
}
// Paginate.
this.paginate(0, this.state.perPage)
}
/**
* Paginate if required after update.
*
* @param {object} prevProps Previous props.
* @since 4.11.6
*/
componentDidUpdate(prevProps) {
// Paginate if list changed.
if (this.props.list !== prevProps.list) {
this.setState({
currentPage: 1
})
this.paginate(0, this.state.perPage)
}
}
/**
* Handle metric item change event.
*
* @param {string} metric Metric key.
* @since 4.11.4
*/
handleMetricChange(metric) {
this.setState({
currentMetric: metric
})
}
/**
* Set paginated list of items.
*
* @param {int} start Start position.
* @param {int} end End position.
* @since 4.11.6
*/
paginate(start, end) {
// Set pagination.
if (this.props.list.length > 0) {
this.setState({
list: this.props.list.slice(start, end),
})
}
}
/**
* Handle pagination event.
*
* Set current page when page navigation happens.
*
* @param {object} data Page data.
* @since 4.11.4
*/
handlePaginate(data) {
this.setState({
currentPage: data.page
})
// Paginate.
this.paginate(data.start, data.end)
}
/**
* Handle table row click event.
*
* Send an wp-ajax request and get the filtered content
* for the applied filters.
*
* @param {object} data Row data.
* @since 4.11.4
*/
async handleRowClick(data) {
// Set loader.
this.setState({
loading: data.name
})
await ajaxRequest(
'wdp-analytics',
{
type: 'filtered',
filter_type: data.type,
filter_value: data.filter,
range: this.props.period.current,
}
).then(response => {
if (response.success) {
// Dispatch filter apply event.
eventBus.dispatch('AnalyticsApplyFilter', {
stats: response.data,
label: data.label,
type: 'list',
filter: {
type: data.type,
filter: data.filter,
}
});
}
});
// Remove loader.
this.setState({
loading: ''
})
}
/**
* Nothing to render as this is base component.
*
* @return {*}
* @since 4.11.4
*/
render() {
const metrics = this.props.metrics;
const ListRow = this.props.row;
return (
<div
data-pane={this.props.type}
className={`${this.props.active ? 'wpmudui-tab-current ' : ''}wpmudui-tab-content`}
>
<div className="wpmudui-search-form">
<PeriodSelector
type={this.props.type}
period={this.props.period}
/>
<MetricSelector
type="posts"
metrics={metrics}
onChange={this.handleMetricChange}
/>
</div>
<div className="wpmudui-table-flushed">
<table className="wpmudui-table">
<thead>
<HeaderRow
title={this.props.title}
metrics={metrics}
currentMetric={this.state.currentMetric}
/>
</thead>
<tbody className="wpmudui-table-sortable">
{this.state.list.map((item) =>
<ListRow
key={item.name}
item={item}
metrics={metrics}
current={this.state.currentMetric}
onClick={this.handleRowClick}
loading={this.state.loading === item.name}
/>
)}
</tbody>
</table>
{this.props.list.length > this.state.perPage &&
<TablePagination
type={this.props.type}
total={this.props.list.length}
page={this.state.currentPage}
perPage={this.state.perPage}
paginate={this.handlePaginate}
/>
}
</div>
</div>
);
}
}